import sys
from PyQt5.QtWidgets import QApplication, QWidget, QGridLayout, QLabel 
from PyQt5.QtGui import QPixmap
import sys
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
 
class ImageGrid(QWidget):
    def __init__(self):
        super().__init__()
        self.initUI()
 
    def initUI(self):
        # 创建一个网格布局
        self.grid = QGridLayout()
         
        # area [0, 0]
        label_0_0 = QLabel(self)
        hbox_0_0 = QHBoxLayout()
        pixmap_0_0 = QPixmap('/media/chyang/data/dataset/detect/MixFormer/lasot/airplane/airplane-1/img/00000001.jpg')  # 替换为图片路径
        label_0_0.setPixmap(pixmap_0_0)
        
        self.scroll_0_0 = QScrollBar()
        self.scroll_0_0.setMaximum(255)
        self.scroll_0_0.sliderMoved.connect(self.sliderval)
        hbox_0_0.addWidget(self.scroll_0_0)
        hbox_0_0.addWidget(label_0_0)
        self.grid.addLayout(hbox_0_0, 0, 0)
        
        # area [0, 1]
        label_0_1 = QLabel(self)
        hbox_0_1 = QHBoxLayout()
        pixmap_0_1 = QPixmap('/media/chyang/data/dataset/detect/MixFormer/lasot/airplane/airplane-1/img/00000001.jpg')  # 替换为图片路径
        label_0_1.setPixmap(pixmap_0_1)
        
        self.scroll_0_1 = QScrollBar()
        self.scroll_0_1.setMaximum(255)
        self.scroll_0_1.sliderMoved.connect(self.sliderval)
        hbox_0_1.addWidget(self.scroll_0_1)
        hbox_0_1.addWidget(label_0_1)
        self.grid.addLayout(hbox_0_1, 0, 1)
        
        # area [1, 0]
        label_1_0 = QLabel(self)
        hbox_1_0 = QHBoxLayout()
        pixmap_1_0 = QPixmap('/media/chyang/data/dataset/detect/MixFormer/lasot/airplane/airplane-1/img/00000001.jpg')  # 替换为图片路径
        label_1_0.setPixmap(pixmap_1_0)
        
        self.scroll_1_0 = QScrollBar()
        self.scroll_1_0.setMaximum(255)
        self.scroll_1_0.sliderMoved.connect(self.sliderval)
        hbox_1_0.addWidget(self.scroll_1_0)
        hbox_1_0.addWidget(label_1_0)
        self.grid.addLayout(hbox_1_0, 1, 0)
                
        # area [1, 1]
        self.btn = QPushButton()
        self.btn.setCheckable(True)
        self.btn.setText("begin select point")
        self.grid.addWidget(self.btn, 1, 1)
        
                
        # 设置窗口的布局为网格布局
        self.setLayout(self.grid)
 
        # 设置窗口的大小
        self.setGeometry(300, 300, 400, 300)
        self.setWindowTitle('Image Grid')
        self.show()
 
    def sliderval(self):
        print( self.scroll_0_0.value(),self.scroll_0_1.value(), self.scroll_1_0.value() )
        palette = QPalette()
        c = QColor(self.s1.value(),self.s2.value(), self.s3.value(),255)
        palette.setColor(QPalette.Foreground,c)
        self.l1.setPalette(palette)
    
    def mousePressEvent(self, event):
        if event.button() == Qt.LeftButton and self.btn.isChecked():
            # 获取鼠标点击位置
            x = event.pos().x()
            y = event.pos().y()
            # 显示鼠标点击位置            
            status = QMessageBox.question(self,"Mouse Click Position", f"X: {x}, Y: {y}", QMessageBox.Yes | QMessageBox.No)#创建一个二次确认框
            
            if status == QMessageBox.Yes:
                print('begin inference'+'\n')#打印当前时间到UI显示，提示完成重启
            else:
                print('reselect point'+'\n')#打印当前时间到UI显示，提示取消重启
 
if __name__ == '__main__':
    app = QApplication(sys.argv)
    ex = ImageGrid()
    sys.exit(app.exec_())